use clap::Parser;

use std::time::{Duration, Instant};
use telnum_gen::phone_gen::PhoneGen;

/// Telephone number generator using the Cartesian product methods in Python and Rust.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Config {
    /// Country code
    #[arg(short, long, default_value_t = 1)]
    country_code: i16,

    /// Prefix for all generated numbers
    #[arg(short, long, default_value_t = 9)]
    prefix: i16,

    /// Output file name with valid path
    #[arg(short, long)]
    file: String,
}

/// Run function
pub fn run() {
    let config: Config = Config::parse();

    println!("RUNNING PROGRAM");
    println!("Country Code: {}", &config.country_code);
    println!("Prefix: {}", &config.prefix);
    println!("Output to: {}", &config.file);

    let combinations = 10 - config.prefix.to_string().len();

    let prefix = format!("{}{}", &config.country_code, &config.prefix);

    let gen = PhoneGen::new(prefix, combinations, config.file);

    let start: Instant = Instant::now();

    gen.generate();

    let end: Duration = start.elapsed();
    println!("Elapsed: {end:.3?}");
}

fn main() {
    const VERSION: &str = env!("CARGO_PKG_VERSION");
    println!("telnum_gen v{VERSION}");

    run();
}
